package org.firebug.metadata.micro.service;

import org.firebug.common.tools.core.BeanTools;
import org.firebug.metadata.client.vo.RegionVO;
import org.firebug.metadata.micro.repository.dao.RegionDAO;
import org.firebug.metadata.micro.repository.po.RegionPO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * 地区服务
 */
@Service
public class RegionService {
    @Resource
    private RegionDAO regionDAO;

    public RegionVO queryByCode(String code) {
        RegionPO po = regionDAO.selectByCode(code);
        return BeanTools.copyProperties(po, RegionVO.class, null);
    }

    public List<RegionVO> listByCode(String code) {
        List<RegionPO> pos = regionDAO.selectByPcode(code);
        return BeanTools.copyProperties(pos, new ArrayList<>(pos.size()), RegionVO.class);
    }

    public List<RegionVO> listByPcodeSector(String pcode, int sector) {
        List<RegionPO> pos = regionDAO.selectByPcodeSector(pcode, sector);
        return BeanTools.copyProperties(pos, new ArrayList<>(pos.size()), RegionVO.class);
    }
}